﻿// (c) Copyright Mikhail Dikov. All other rights reserved.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI;
using WebPartExtenders;
using System.Xml.Serialization;
using System.ComponentModel;

// TODO: Add a color picker property to the web part settings

namespace WebPartExtenderToolkit
{
    [ToolboxData("<{0}:RoundedCornersWebPart runat=server></{0}:RoundedCornersWebPart>")]
    [XmlRoot(Namespace = "RoundedCornersWebPart")]
    public class RoundedCornersWebPart : ExtenderWebPartBase
    {
        private RoundedCornersExtender extender;

        protected override void CreateChildControls()
        {            
            base.CreateChildControls();
            extender = new RoundedCornersExtender();
            Controls.Add(extender);
            ChildControlsCreated = true;
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            extender.TargetControlID = this.TargetControlID;
            extender.Enabled = Enabled && !string.IsNullOrEmpty(TargetControlID);
            extender.BehaviorID = this.BehaviorID;
            extender.ID = this.ID + "extender";
            extender.Radius = Radius;
            extender.Corners = Corners;
           //Always hide the extender control chrome, because it'll show up as an empty webpart
            ChromeType = PartChromeType.None;
            Title = "Rounded Corners WebPart Extender";

        }

        #region RoundedCornersExtender Properies

        [Category("Extender"),
        WebBrowsable(true),
        WebDisplayName("Radius"),
        WebDescription("The radius of the corners (and height of the added area). Default is 5."),
        Browsable(true), 
        Personalizable(PersonalizationScope.Shared),
        DisplayName("Radius"),
        Description("The radius of the corners (and height of the added area). Default is 5.")]
        public int Radius { get; set; }

        [Category("Extender"),
        WebBrowsable(true),
        WebDisplayName("Corners"),
        WebDescription("The corners of the target panel that will be rounded (can be None, TopLeft, TopRight, BottomRight, BottomLeft, Top, Right, Bottom, Left, or All)."),
        Browsable(true), 
        Personalizable(PersonalizationScope.Shared),
        DisplayName("Corners"),
        Description("The corners of the target panel that will be rounded (can be None, TopLeft, TopRight, BottomRight, BottomLeft, Top, Right, Bottom, Left, or All).")]
        public BoxCorners Corners { get; set; }

	    #endregion

    }
}
